﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Webcar.BLL;
using ToolsLayer;
using System.Data;

namespace Webcar.UI
{
    public partial class RecentGS : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (this.IsPostBack) return;
                string sql = string.Format(@"select top 10 a.msg_xh,a.note,a.oper_name,send_time_str from v_send_msg a join SEND_MSG_log b 
               on a.msg_xh = b.msg_xh join v_all_users c on b.man_code=c.account
                and (b.man_code = '{0}' ) order by send_time desc", CurrentUser.LoginUserID);
                
                DataSet ds = DB.ExecuteDataset(sql);
                this.Repeater1.DataSource = ds;
                this.Repeater1.DataBind();

                string sql2 = string.Format(@"select top 14 a.msg_xh,a.note,a.oper_name,send_time_str from v_send_msg a where a.writer 
                                = '{0}' order by send_time desc", CurrentUser.LoginUserID);

                DataSet ds2 = DB.ExecuteDataset(sql2);
                this.Repeater2.DataSource = ds2;
                this.Repeater2.DataBind();

            }
            catch (Exception ex)
            {
                new CurrentUser().LogError(ex);
            }
        }

        protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            HyperLink link = (HyperLink)e.Item.FindControl("hyperlink1");
            DataRowView row = e.Item.DataItem as DataRowView;
            string xh = row["msg_xh"].ToString();
            string url = "UI/gsViewPop.aspx?id=" + xh;
            link.NavigateUrl = "javascript:openDialog('"+url+"',600,350);";

            Label label = (Label)e.Item.FindControl("newlabel");
            //DateTime date = DateTime.Parse(row["send_time_str"].ToString());
            //label.Visible = (DateTime.Now - date).TotalDays < 7;

            InfoChecker ic = new InfoChecker();
            label.Visible = !ic.InfoIsRead(xh, InfoCheckType.Gs);
        }
    }
}